#include "PlayLayer.h"
#include "PlayerBoard.h"
#include "ForSaleBoard.h"
#include "OperateBoard.h"
#include "DataManage.h"
#include "PhaseManage.h"
#include "ScoreBoard.h"
#include "AudioManage.h"

PlayLayer* PlayLayer::thisLayer;

PlayLayer* PlayLayer::getInstance()
{
	return thisLayer;
}

Scene* PlayLayer::createScene()
{
	Scene* playScene = Scene::create();
	Layer* playLayer = PlayLayer::create();

	playScene->addChild(playLayer);
	thisLayer = (PlayLayer*)playLayer;

	return playScene;
}

bool PlayLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();

	LayerColor* pBaseTemp = LayerColor::create(Color4B(252, 241, 142, 255));
	addChild(pBaseTemp, ZORDER_BOARD_0);

	PlayerBoard* pPlayerBoard = PlayerBoard::create();
	pPlayerBoard->setPosition(visibleSize.width / 2, visibleSize.height * 0.89f);
	addChild(pPlayerBoard, ZORDER_BOARD_1);

	ForSaleBoard* pForSaleBoard = ForSaleBoard::create();
	pForSaleBoard->setPlayerBoard(pPlayerBoard);
	pForSaleBoard->setPosition(visibleSize.width / 2, visibleSize.height * 0.558f);
	addChild(pForSaleBoard, ZORDER_BOARD_2);

	OperateBoard* pOperateBoard = OperateBoard::create();
	pOperateBoard->setPosition(visibleSize.width / 2, visibleSize.height * 0.17f);
	addChild(pOperateBoard, ZORDER_BOARD_3);

	PhaseManage::getInstance()->start();

	runAction(Sequence::create(DelayTime::create(1.0f), CallFunc::create([](){AudioManage::playPlayMusic(); }), nullptr));

	return true;
}

